<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="first+='~'">First: {{ first }}</button>
        <button @click="last+='!'">Last: {{ last }}</button>
        <button @click="msg = msg.substr(0, msg.length - 1)">Msg: {{ msg }}</button>

        <hr />
        <!-- 模板中直接做逻辑 -->
        <p>FullName: {{ first + '' + last }}</p>
        <!-- 将逻辑做到计算属性中，然后使用计算属性 -->
        <p>FullName: {{ fullName }}</p>

        <hr />
        <p>反转Msg: {{ msg.split('').reverse().join('') }}</p>
        <p>反转Msg: {{ reverseMsg }}</p>
    </div>

    <script type="module">
        import { createApp } from './lib/vue3.esm.browser.js'

        createApp({

            data() {
                return {
                    first: '张',
                    last: '三',

                    msg: 'Hello'
                }
            },

            /**
             * 声明计算属性
             */
            computed: {
                fullName() {
                    return this.first + '' + this.last
                },

                reverseMsg() {
                    return this.msg.split('').reverse().join('')
                }
            }

        }).mount('#app')
    </script>
</body>

</html>